/**
 * main.js for www.debenhams.com
 * last updated 15 Oct 2009, 12:19
 */


/***********************************************
	Code runs as soon as this JS file is loaded
	Code adds the class 'jsEnabled' to the HTML tag
	--------------------------------------------
	Add the class 'jsEnabled' to the HTML tag on a page.
	Runs as soon as this JS file is loaded, as the html tag
	should be the first tag available and doesn't require the
	documentent to be DOM ready.
***********************************************/
if (document.documentElement && document.getElementById) {
    var docClass = document.documentElement.className != null ? document.documentElement.className : document.documentElement.getAttribute('class');
    docClass =  docClass !='' ? docClass + ' jsEnabled' : 'jsEnabled';
    document.documentElement.setAttribute('class',docClass);
    document.documentElement.className = docClass; //For IE
}


// on document ready...
$(function() {

	// AKQA...
	if(/MSIE 6/i.test(navigator.userAgent)) {
		// wraps a tags round buttons so the :hover states show up in effing msie 6
		$('input[type=button]').add('input[type=submit]').wrap( '<a href="#"></a>' );
	}
	if(/Firefox/i.test(navigator.userAgent)) {
		$('.custom_input').addClass('firefox_pad');
	}
	$('#utility li:first-child a').addClass('no_background');
	$('#shopping_bag li:last-child a').addClass('no_background');

	// removes the right padding from every third ad image so it aligns nicely
	$('.advert_third').filter(function(index) { return (index+1)%3==0; }).addClass('row_end');
	// adds divs with background images on selected tabs on nav panel
	
	/*$('#main_navigation li.selected a').wrap('<div class="outer"><div class="mid"><div class="inner"></div></div></div>');KT*/

	$('.link_tray a').click(function() {
//		alert($(this).text());
	});
	$('.advert_third a').click(function() {
//		alert($(this).text());
	});

	// left hand navigation
	// upon click on navigation list item
	// perform switch - if child list open it
	// if no child list look for a tag and launch href
	$('ul.navigation li a.facet_title').click(function() {
		if($(this).parent().find('ul').length > 0) {
			$(this).parent().toggleClass('open');
			return false;
		}
	});

	$('.custom_checkbox input[type=checkbox]').addClass('no_display');
	$('.custom_checkbox li').click(function() {
		$(this).toggleClass('selected');
		handleSelection();
		return false;
	});
	$('.custom_checkbox li').keypress(function(e) {
		if(e.which == 13 || e.which == 32) { $(this).toggleClass('selected'); handleSelection(); return false; }
	});
	
	
	$('.category_value a').wrapInner('<div class="cat_outer"><div class="cat_mid"><div class="cat_inner"></div></div></div>');
	// mouseovers on product images
	$('.product_detail').mouseover(function() {
		$(this).addClass('highlight');
	});
	$('.product_detail').mouseout(function() {
		$(this).removeClass('highlight');
	});
	// links for product panels
	$('.product_detail').click(function() {
//		alert($(this).find('.brand_name').text() + ' ' + $(this).find('.product_name').text() + ', ' + $(this).find('.product_price').text());
	});
	// function to remove right padding from end of row of products, hard-coded by index
	//	$('.product_detail').filter(function(index) { return (index+1)%4==0; }).addClass('row_end');
	// function to remove right padding from end of row of products, dynamic according to screen position
	
	/**$('.product_detail').filter(
			function(index) {
				return !$(this).next().position() || $(this).position().top < $(this).next().position().top;
//				return $(this).next() && $(this).next().position() && $(this).position().top < $(this).next().position().top;
			}).addClass('row_end');**/
			
});

function handleSelection() {

}